home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / netconf / firewall.c < prev    next >
C/C++ Source or Header  |  1996-07-29  |  16KB  |  685 lines

  1. #pragma implementation
  2. #include <string.h>
  3. #include <stdlib.h>
  4.     #include <sys/types.h>
  5.     #include <sys/socket.h>
  6.     #include <netinet/in.h>
  7.     #include <linux/ip.h>
  8.     #include <linux/tcp.h>
  9.     #include <linux/udp.h>
  10.     #include <linux/icmp.h>
  11.     #include <linux/if.h>
  12.     #include <linux/ip_fw.h>
  13. #include "netconf.h"
  14. #include "internal.h"
  15. #include "firewall.h"
  16. #include "../dialog/dialog.h"
  17. #include "../misc/misc.h"
  18. #include "../userconf/userconf.h"
  19. #include "../paths.h"
  20. #include "netconf.m"
  21.  
  22. #ifndef IP_FW_POLICY_IN
  23.     /* #Specification: firewall / compatibility
  24.         linuxconf requires a kernel newer than 1.3.66 (or close) to
  25.         support firewalling. Linuxconf works with older kernels but
  26.         won't activate firewalling rules.
  27.     */
  28.     /* These are just here so it compiles */
  29.     #define IP_FW_APPEND_IN        0
  30.     #define IP_FW_APPEND_OUT    0
  31.     #define IP_FW_APPEND_FWD    0
  32.  
  33.     #define IP_FW_POLICY_IN        0
  34.     #define IP_FW_POLICY_OUT    0
  35.     #define IP_FW_POLICY_FWD    0
  36.  
  37.     #define IP_FW_FLUSH_IN        0
  38.     #define IP_FW_FLUSH_OUT        0
  39.     #define IP_FW_FLUSH_FWD        0
  40.  
  41.     #define FIREWALL_NONE
  42. #endif
  43. extern NETCONF_HELP_FILE help_ipfw;
  44.  
  45. static CONFIG_FILE ip_forward (PROC_NET_IP_FORWARD,help_ipfw
  46.     ,CONFIGF_OPTIONNAL|CONFIGF_PROBED);
  47. static CONFIG_FILE ip_block (PROC_NET_IP_BLOCK,help_ipfw
  48.     ,CONFIGF_OPTIONNAL|CONFIGF_PROBED);
  49. static CONFIG_FILE ip_input (PROC_NET_IP_INPUT,help_ipfw
  50.     ,CONFIGF_OPTIONNAL|CONFIGF_PROBED);
  51. static CONFIG_FILE ip_output (PROC_NET_IP_OUTPUT,help_ipfw
  52.     ,CONFIGF_OPTIONNAL|CONFIGF_PROBED);
  53. static CONFIG_FILE ip_acct (PROC_NET_IP_ACCT,help_ipfw
  54.     ,CONFIGF_OPTIONNAL|CONFIGF_PROBED);
  55.  
  56. static CONFIG_FILE f_current_acct (VAR_RUN_FIREWALL_ACCT,help_ipfw
  57.     ,CONFIGF_GENERATED|CONFIGF_OPTIONNAL|CONFIGF_ERASED);
  58. static CONFIG_FILE f_current_block (VAR_RUN_FIREWALL_BLOCK,help_ipfw
  59.     ,CONFIGF_GENERATED|CONFIGF_OPTIONNAL|CONFIGF_ERASED);
  60. static CONFIG_FILE f_current_forwd (VAR_RUN_FIREWALL_FORWD,help_ipfw
  61.     ,CONFIGF_GENERATED|CONFIGF_OPTIONNAL|CONFIGF_ERASED);
  62. static CONFIG_FILE f_current_output (VAR_RUN_FIREWALL_OUTPUT,help_ipfw
  63.     ,CONFIGF_GENERATED|CONFIGF_OPTIONNAL|CONFIGF_ERASED);
  64.  
  65.  
  66.  
  67. class IPFW_RULES: public ARRAY{
  68. public:
  69.     char active;
  70. private:
  71.     virtual IPFW_RULE *newrule()=0;
  72.     virtual IPFW_RULE *newrule(const char *pt)=0;
  73.     virtual int save()=0;
  74.     virtual int kernelok()=0;
  75.     virtual int enable(int doit, SSTRING *collect)=0;
  76. public:
  77.     virtual int disable(int doit, SSTRING *collect)=0;
  78.     /*~PROTOBEG~ IPFW_RULES */
  79. public:
  80.     void edit (void);
  81.     IPFW_RULE *getitem (int no);
  82. protected:
  83.     void init (const char *key,
  84.          const char *key_active);
  85. private:
  86.     void reset_nbbitmsk (void);
  87. protected:
  88.     int savek (const char *key,
  89.          const char *key_active);
  90. public:
  91.     int setup (int doit, SSTRING *collect);
  92.     /*~PROTOEND~ IPFW_RULES */
  93. };
  94. class IPFW_RULES_FORWARD: public IPFW_RULES{
  95.     /*~PROTOBEG~ IPFW_RULES_FORWARD */
  96. public:
  97.     IPFW_RULES_FORWARD (void);
  98.     int disable (int doit, SSTRING *collect);
  99.     int enable (int doit, SSTRING *collect);
  100.     int kernelok (void);
  101. protected:
  102.     IPFW_RULE *newrule (const char *pt);
  103.     IPFW_RULE *newrule (void);
  104. public:
  105.     int save (void);
  106.     /*~PROTOEND~ IPFW_RULES_FORWARD */
  107. };
  108. class IPFW_RULES_INPUT: public IPFW_RULES{
  109.     /*~PROTOBEG~ IPFW_RULES_INPUT */
  110. public:
  111.     IPFW_RULES_INPUT (void);
  112.     int disable (int doit, SSTRING *collect);
  113.     int enable (int doit, SSTRING *collect);
  114.     int kernelok (void);
  115. protected:
  116.     IPFW_RULE *newrule (const char *pt);
  117.     IPFW_RULE *newrule (void);
  118. public:
  119.     int save (void);
  120.     /*~PROTOEND~ IPFW_RULES_INPUT */
  121. };
  122. class IPFW_RULES_OUTPUT: public IPFW_RULES{
  123.     /*~PROTOBEG~ IPFW_RULES_OUTPUT */
  124. public:
  125.     IPFW_RULES_OUTPUT (void);
  126.     int disable (int doit, SSTRING *collect);
  127.     int enable (int doit, SSTRING *collect);
  128.     int kernelok (void);
  129. protected:
  130.     IPFW_RULE *newrule (const char *pt);
  131.     IPFW_RULE *newrule (void);
  132. public:
  133.     int save (void);
  134.     /*~PROTOEND~ IPFW_RULES_OUTPUT */
  135. };
  136.  
  137. PUBLIC IPFW_RULE *IPFW_RULES::getitem(int no)
  138. {
  139.     return (IPFW_RULE*)ARRAY::getitem(no);
  140. }
  141.  
  142. static char ACTIVEF[] = "activef";
  143. static char ACTIVEB[] = "activeb";
  144. static char ACTIVEO[] = "activeo";
  145. //static char ACTIVEA[] = "activea";
  146.  
  147. PROTECTED void IPFW_RULES::init (const char *key, const char *key_active)
  148. {
  149.     SSTRINGS strs;
  150.     active = linuxconf_getvalnum (FIREWALL,key_active,0);
  151.     linuxconf_getall (FIREWALL,key,strs,0);
  152.     int nb = strs.getnb();
  153.     for (int i=0; i<nb; i++){
  154.         SSTRING *s = strs.getitem(i);
  155.         add (newrule (s->get()));
  156.     }
  157.     rstmodified();
  158. }
  159.  
  160. PUBLIC IPFW_RULES_FORWARD::IPFW_RULES_FORWARD()
  161. {
  162.     init (FORWARD,ACTIVEF);
  163. }
  164.  
  165. PUBLIC IPFW_RULES_INPUT::IPFW_RULES_INPUT()
  166. {
  167.     init (BLOCK,ACTIVEB);
  168. }
  169. PUBLIC IPFW_RULES_OUTPUT::IPFW_RULES_OUTPUT()
  170. {
  171.     init (OUTPUT,ACTIVEO);
  172. }
  173.  
  174.  
  175. PROTECTED int IPFW_RULES::savek(const char *key, const char *key_active)
  176. {
  177.     int ret = -1;
  178.     if (perm_rootaccess("update firewalling configuration")){
  179.         int nb = getnb();
  180.         linuxconf_replace (FIREWALL,key_active,active);
  181.         linuxconf_removeall(FIREWALL,key);
  182.         for (int i=0; i<nb; i++){
  183.             getitem(i)->save();
  184.         }
  185.         ret = linuxconf_save();
  186.     }
  187.     return ret;
  188. }
  189.  
  190.  
  191. PUBLIC int IPFW_RULES_FORWARD::save()
  192. {
  193.     return IPFW_RULES::savek (FORWARD,ACTIVEF);
  194. }
  195.  
  196. PROTECTED IPFW_RULE *IPFW_RULES_FORWARD::newrule()
  197. {
  198.     return new IPFW_RULE_FORWARD;
  199. }
  200. PROTECTED IPFW_RULE *IPFW_RULES_FORWARD::newrule(const char *pt)
  201. {
  202.     return new IPFW_RULE_FORWARD (pt);
  203. }
  204.  
  205. PUBLIC int IPFW_RULES_INPUT::save()
  206. {
  207.     return IPFW_RULES::savek (BLOCK,ACTIVEB);
  208. }
  209. PROTECTED IPFW_RULE *IPFW_RULES_INPUT::newrule()
  210. {
  211.     return new IPFW_RULE_INPUT;
  212. }
  213. PROTECTED IPFW_RULE *IPFW_RULES_INPUT::newrule(const char *pt)
  214. {
  215.     return new IPFW_RULE_INPUT (pt);
  216. }
  217.  
  218. PUBLIC int IPFW_RULES_OUTPUT::save()
  219. {
  220.     return IPFW_RULES::savek (OUTPUT,ACTIVEO);
  221. }
  222. PROTECTED IPFW_RULE *IPFW_RULES_OUTPUT::newrule()
  223. {
  224.     return new IPFW_RULE_OUTPUT;
  225. }
  226. PROTECTED IPFW_RULE *IPFW_RULES_OUTPUT::newrule(const char *pt)
  227. {
  228.     return new IPFW_RULE_OUTPUT (pt);
  229. }
  230.  
  231. /*
  232.     Edit all firewalling rules
  233. */
  234. PUBLIC void IPFW_RULES::edit()
  235. {
  236.     if (perm_rootaccess("edit firewalling rules")){
  237.         int choice = 0;
  238.         while (1){
  239.             int nb = getnb();
  240.             const char **menuopt
  241.                 = (const char**)malloc(((nb*2)+1)*sizeof(char*));
  242.             int i;
  243.             int ii=0;
  244.             for (i=0; i<nb; i++){
  245.                 menuopt[ii++] = " ";
  246.                 char buf[100];
  247.                 getitem(i)->present (buf);
  248.                 menuopt[ii++] = strdup(buf);
  249.             }
  250.             menuopt[ii] = NULL;
  251.             MENU_STATUS code = xconf_menu(
  252.                 MSG_U(T_EDITFIRE,"Edit firewalling rules")
  253.                 ,MSG_U(I_EDITFIRE
  254.                     ,"You are allowed to edit/add/deleted\n"
  255.                      "rules for forwarding packets")
  256.                 ,help_ipfw
  257.                 ,NULL
  258.                 ,NULL
  259.                 ,NULL
  260.                 ,MSG_U(I_NEWRULES,"new rules")
  261.                 ,menuopt
  262.                 ,choice);
  263.             IPFW_RULE *item = NULL;
  264.             if (choice >=0 && choice < nb){
  265.                 item = getitem(choice);
  266.             }
  267.             for (i=0; i<nb; i++) free ((char*)(menuopt[i*2+1]));
  268.             free ((char**)menuopt);
  269.             if (code == MENU_ESCAPE || code == MENU_QUIT){
  270.                 break;
  271.             }else if (perm_rootaccess("modify firewalling rules")){
  272.                 if (code == MENU_OK){
  273.                     if (item != NULL){
  274.                         int ok = item->edit();
  275.                         if (ok >= 0){
  276.                             if (ok == 1) remove_del(item);
  277.                             save();
  278.                         }
  279.                     }
  280.                 }else if (code == MENU_ADD){
  281.                     IPFW_RULE *a = newrule();
  282.                     if (a->edit() == 0){
  283.                         add (a);
  284.                         save();
  285.                     }else{
  286.                         delete a;
  287.                     }
  288.                 }
  289.             }
  290.         }
  291.     }
  292. }
  293.  
  294. /*
  295.     Turn off completly blocking
  296. */
  297. PUBLIC int IPFW_RULES_INPUT::disable(
  298.     int doit,
  299.     SSTRING *collect)
  300. {
  301.     // The order is important as the reverse will break connectivity
  302.     // for a moment.
  303.     return ipfw_policy (doit,collect,IP_FW_POLICY_IN,IP_FW_F_ACCEPT) == -1
  304.         || ipfw_flush(doit,collect,IP_FW_FLUSH_IN) == -1
  305.         ? -1 : 0;
  306. }
  307. /*
  308.     Turn on blocking
  309. */
  310. PUBLIC int IPFW_RULES_INPUT::enable(
  311.     int doit,
  312.     SSTRING *collect)
  313. {
  314.     struct ip_fw bf;
  315.     ipfw_baseinit ("127.0.0.1","all"
  316.         ,"127.0.0.1","255.255.255.255","",""
  317.         ,"127.0.0.1","255.255.255.255","",""
  318.         ,bf);
  319.     return ipfw_append (doit,collect,IP_FW_APPEND_IN,bf) == -1
  320.         || ipfw_policy (doit,collect,IP_FW_POLICY_IN,0) == -1
  321.         ? -1 : 0;
  322. }
  323. /*
  324.     check if the kernel do support blocking
  325. */
  326. PUBLIC int IPFW_RULES_INPUT::kernelok()
  327. {
  328.     int ret = 1;
  329.     if (!ip_block.exist() && !ip_input.exist()){
  330.         static char shutoff = 0;
  331.         if (!shutoff){
  332.             xconf_error (MSG_U(ERR_BLOCKING
  333.                 ,"The kernel does not support\n"
  334.                 "IP_BLOCKING, reconfigure it"));
  335.             shutoff = 1;
  336.         }
  337.         ret = 0;
  338.     }
  339.     return ret;
  340. }
  341. /*
  342.     Turn off completly forwarding
  343. */
  344. PUBLIC int IPFW_RULES_OUTPUT::disable(
  345.     int doit,
  346.     SSTRING *collect)
  347. {
  348.     return ipfw_policy (doit,collect,IP_FW_POLICY_OUT,IP_FW_F_ACCEPT) == -1
  349.         || ipfw_flush(doit,collect,IP_FW_FLUSH_OUT) == -1
  350.         ? -1 : 0;
  351. }
  352. /*
  353.     Turn on forwarding firewall
  354. */
  355. PUBLIC int IPFW_RULES_OUTPUT::enable(
  356.     int doit,
  357.     SSTRING *collect)
  358. {
  359.     /* #Specification: firewall / strategy
  360.         The blocking and outputing mecanism use a positive
  361.         logic. Everything is deny at first. Each rule supplied
  362.         by the user is opening a new hole.
  363.  
  364.         The firewalling code of Linux is more general than that.
  365.         It should be good enough for most firewall and simple
  366.         for users/admin too.
  367.     */
  368.     struct ip_fw bf;
  369.     ipfw_baseinit ("127.0.0.1","all"
  370.         ,"127.0.0.1","255.255.255.255","",""
  371.         ,"127.0.0.1","255.255.255.255","",""
  372.         ,bf);
  373.     return ipfw_append (doit,collect,IP_FW_APPEND_OUT,bf) == -1
  374.         || ipfw_policy (doit,collect,IP_FW_POLICY_OUT,0) == -1
  375.         ? -1 : 0;
  376. }
  377. /*
  378.     Turn off completly forwarding
  379. */
  380. PUBLIC int IPFW_RULES_FORWARD::disable(
  381.     int doit,
  382.     SSTRING *collect)
  383. {
  384.     return ipfw_policy (doit,collect,IP_FW_POLICY_FWD,IP_FW_F_ACCEPT) == -1
  385.         || ipfw_flush(doit,collect,IP_FW_FLUSH_FWD) == -1
  386.         ? -1 : 0;
  387. }
  388. /*
  389.     Turn on forwarding firewall
  390. */
  391. PUBLIC int IPFW_RULES_FORWARD::enable(
  392.     int doit,
  393.     SSTRING *collect)
  394. {
  395.     return ipfw_policy (doit,collect,IP_FW_POLICY_FWD,0) == -1
  396.         ? -1 : 0;
  397. }
  398. /*
  399.     check if the kernel do support forwarding
  400. */
  401. PUBLIC int IPFW_RULES_FORWARD::kernelok()
  402. {
  403.     int ret = 1;
  404.     if (!ip_forward.exist()){
  405.         static char shutoff = 0;
  406.         if (!shutoff){
  407.             xconf_error (MSG_U(ERR_FORWARDING
  408.                 ,"The kernel does not support\n"
  409.                 "IP_FORWARDING, reconfigure it"));
  410.             shutoff = 1;
  411.         }
  412.         ret = 0;
  413.     }
  414.     return ret;
  415. }
  416. /*
  417.     check if the kernel do support outputint
  418. */
  419. PUBLIC int IPFW_RULES_OUTPUT::kernelok()
  420. {
  421.     int ret = 1;
  422.     if (!ip_output.exist()){
  423.         static char shutoff = 0;
  424.         if (!shutoff){
  425.             xconf_error (MSG_U(ERR_OUTPUT
  426.                 ,"The kernel does not support\n"
  427.                 "IP_OUTPUTING, reconfigure it"));
  428.             shutoff = 1;
  429.         }
  430.         ret = 0;
  431.     }
  432.     return ret;
  433. }
  434.  
  435. /*
  436.     Compare by netmask. host netmask will be first, 0.0.0.0 will be last
  437. */
  438. static int cmp_by_netmask_from (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2)
  439. {
  440.     IPFW_RULE *r1 = (IPFW_RULE*)o1;
  441.     IPFW_RULE *r2 = (IPFW_RULE*)o2;
  442.     return r2->nbbitmask_from() - r1->nbbitmask_from();
  443. }
  444. /*
  445.     Compare by netmask. host netmask will be first, 0.0.0.0 will be last
  446. */
  447. static int cmp_by_netmask_to (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2)
  448. {
  449.     IPFW_RULE *r1 = (IPFW_RULE*)o1;
  450.     IPFW_RULE *r2 = (IPFW_RULE*)o2;
  451.     return r2->nbbitmask_to() - r1->nbbitmask_to();
  452. }
  453.  
  454. PRIVATE void IPFW_RULES::reset_nbbitmsk()
  455. {
  456.     int n = getnb();    
  457.     for (int i=0; i<n; i++){
  458.         IPFW_RULE *r = getitem(i);
  459.         r->from.nbbit_msk = -1;
  460.         r->to.nbbit_msk = -1;
  461.     }
  462. }
  463.  
  464. /*
  465.     Apply the firewalling rules
  466. */
  467. PUBLIC int IPFW_RULES::setup(
  468.     int doit,
  469.     SSTRING *collect)
  470. {
  471.     int ret = 0;
  472.     /* #Specification: netconf / firewalling / logic
  473.         The firewalling strategy is this. When activating
  474.         one rule set (blocking, forwarding), you are closing
  475.         the door (policy deny). Each rule you enter open
  476.         a door. This is less general than using ipfw directly
  477.         but much simpler and enough for most usage.
  478.  
  479.         Comments are more than welcome about this.
  480.  
  481.         While setting the rules, we set the policy to accept.
  482.         We set it to deny at the end of the rule sequence. This
  483.         prevent some interruption in the networking while
  484.         installing the rules. If we would have start by denying
  485.         everything, we could have add all kind of network timeout
  486.         while trying to set the rules. Quite often, setting rules
  487.         involve DNS access.
  488.     */
  489.     if (active){
  490.         if (!kernelok()
  491.             || disable(doit,collect)==-1){
  492.             ret = -1;
  493.         }else{
  494.             ret = 0;
  495.             reset_nbbitmsk();
  496.             sort (cmp_by_netmask_from);
  497.             int nbr = getnb();
  498.             int i;
  499.             for (i=0; i<nbr; i++){
  500.                 IPFW_RULE *r = getitem(i);
  501.                 ret |= r->setup_left(doit,collect);
  502.             }
  503.             sort (cmp_by_netmask_to);
  504.             for (i=0; i<nbr; i++){
  505.                 IPFW_RULE *r = getitem(i);
  506.                 ret |= r->setup_right(doit,collect);
  507.             }
  508.             ret = enable (doit,collect);
  509.         }
  510.     }
  511.     return ret;
  512. }
  513. #ifndef FIREWALL_NONE
  514.  
  515. static int firewall_setup (
  516.     IPFW_RULES &rules,
  517.     CONFIG_FILE &f_current)
  518. {
  519.     int ret = 0;
  520.     SSTRING collect;
  521.     if (rules.setup(0,&collect) != -1){
  522.         SSTRING current;
  523.         /* #Specification: firewalling / update needed
  524.             Probing the firewalling information to find
  525.             out if the current configuration is already
  526.             configured in the kernel is not easy. A trick
  527.             is used here. All the command generated to
  528.             configured the kernel are saved in the files
  529.             /var/run/firewall.{acct,block,forwd}.
  530.  
  531.             When probing the firewall setup, we generate
  532.             the command in a string and compare that string
  533.             with the content of the file. If there is
  534.             any mismatch, the complete firewalling sequence
  535.             is reprogrammend in the kernel and the string
  536.             is saved in /var/run/firewall.state.
  537.         */
  538.         FILE *fin = f_current.fopen ("r");
  539.         if (fin != NULL){
  540.             char buf[1000];
  541.             while (fgets(buf,sizeof(buf)-1,fin)!=NULL){
  542.                 current.append (buf);
  543.             }
  544.             fclose (fin);
  545.         }
  546.         if (current.cmp(collect)!=0){
  547.             if(collect.is_empty()){
  548.                 // No rules needed but the firewall must be desactivated
  549.                 rules.disable(0,&collect);
  550.                 if (!simul_ison()){
  551.                     f_current.unlink();
  552.                     rules.disable(1,NULL);
  553.                 }
  554.             }else{
  555.                 if (!simul_ison()){
  556.                     ret = rules.setup(1,NULL);
  557.                     if (ret != -1){
  558.                         FILE *fout = f_current.fopen ("w");
  559.                         if (fout != NULL){
  560.                             fputs (collect.get(),fout);
  561.                             fclose (fout);
  562.                         }
  563.                     }
  564.                 }
  565.             }
  566.             net_prtlog ("%s",collect.get());
  567.         }
  568.     }
  569.     return ret;
  570. }
  571. #endif
  572. /*
  573.     Install the firewalling rules in the kernel.
  574.     Return -1 if any errors
  575. */
  576. int firewall_setup()
  577. {
  578.     int ret = -1;
  579.     IPFW_RULES_FORWARD frules;
  580.     IPFW_RULES_INPUT brules;
  581.     IPFW_RULES_OUTPUT orules;
  582.     if (frules.active || brules.active || orules.active){
  583.         #ifdef FIREWALL_NONE
  584.             xconf_error (MSG_U(E_FWOLDKERN
  585.                 ,"Linuxconf was compiled on an old kernel and does not\n"
  586.                  "support firewalling properly. No rule will be activated."));
  587.         #else
  588.             if (perm_rootaccess("activating the firewalling configuration")){
  589.                 if (ipfw_open() != -1
  590.                     && firewall_setup (frules,f_current_forwd) != -1
  591.                     && firewall_setup (brules,f_current_block) != -1
  592.                     && firewall_setup (orules,f_current_output) != -1){
  593.                     ipfw_close();
  594.                     ret = 0;
  595.                 }
  596.             }
  597.         #endif
  598.     }
  599.     return ret;
  600. }
  601. /*
  602.     Reset the firewalling rules in the kernel.
  603.     Return -1 if any errors
  604. */
  605. int firewall_reset()
  606. {
  607.     int ret = -1;
  608.     if (perm_rootaccess("disabling the firewalling configuration")){
  609.         IPFW_RULES_FORWARD frules;
  610.         IPFW_RULES_INPUT brules;
  611.         IPFW_RULES_OUTPUT orules;
  612.         f_current_forwd.unlink();
  613.         f_current_block.unlink();
  614.         f_current_output.unlink();
  615.         if (ipfw_open() != -1
  616.             && frules.disable(1,NULL) != -1
  617.             && brules.disable(1,NULL) != -1
  618.             && orules.disable(1,NULL) != -1){
  619.             ipfw_close();
  620.             ret = 0;
  621.         }
  622.     }
  623.     return ret;
  624. }
  625. /*
  626.     Edit the default configuration of the firewall
  627. */
  628. void firewall_editc()
  629. {
  630.     IPFW_RULES_FORWARD frules;
  631.     IPFW_RULES_INPUT brules;
  632.     IPFW_RULES_OUTPUT orules;
  633.     DIALOG dia;
  634.     dia.newf_chk (MSG_U(F_BRULES,"Inputing rules"),brules.active,"are active");
  635.     dia.newf_chk (MSG_U(F_FRULES,"forwarding rules"),frules.active,"are active");
  636.     dia.newf_chk (MSG_U(F_ORULES,"outputing rules"),orules.active,"are active");
  637.     if (dia.edit("Global control of the firewalling/accounting"
  638.         ,"You are allowed to disable/enable all rule sets\n"
  639.          "without deleting them. Beware that activating\n"
  640.          "an empty rule set is closing all doors!!!"
  641.         ,help_ipfw.getpath()
  642.         ,0)==MENU_ACCEPT){
  643.         brules.save();
  644.         frules.save();
  645.         orules.save();
  646.     }
  647.         
  648. }
  649. /*
  650.     Edit forwarding rules
  651. */
  652. void firewall_editf()
  653. {
  654.     IPFW_RULES_FORWARD frules;
  655.     frules.edit();
  656. }
  657. /*
  658.     Edit blocking rules
  659. */
  660. void firewall_editb()
  661. {
  662.     IPFW_RULES_INPUT brules;
  663.     brules.edit();
  664. }
  665. /*
  666.     Edit outputing rules
  667. */
  668. void firewall_edito()
  669. {
  670.     IPFW_RULES_OUTPUT brules;
  671.     brules.edit();
  672. }
  673.  
  674. /*
  675.     Edit accounting rules
  676. */
  677. void firewall_edita()
  678. {
  679.     xconf_notice ("Sorry, not implemented yet!");
  680. //    IPFW_RULES_ACCT arules;
  681. //    arules.edit();
  682. }
  683.  
  684.  
  685.